home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
cmuscheme.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-01-20
|
17KB
|
414 lines
;;; cmuscheme.el --- Scheme process in a buffer. Adapted from tea.el.
;; Copyright (C) 1988, 1994 Free Software Foundation, Inc.
;; Author: Olin Shivers <olin.shivers@cs.cmu.edu>
;; Maintainer: FSF
;; Keywords: processes, lisp
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This is a customisation of comint-mode (see comint.el)
;;
;; Written by Olin Shivers (olin.shivers@cs.cmu.edu). With bits and pieces
;; lifted from scheme.el, shell.el, clisp.el, newclisp.el, cobol.el, et al..
;; 8/88
;;
;; Please send me bug reports, bug fixes, and extensions, so that I can
;; merge them into the master source.
;;
;; The changelog is at the end of this file.
;;
;; NOTE: MIT Cscheme, when invoked with the -emacs flag, has a special user
;; interface that communicates process state back to the superior emacs by
;; outputting special control sequences. The gnumacs package, xscheme.el, has
;; lots and lots of special purpose code to read these control sequences, and
;; so is very tightly integrated with the cscheme process. The cscheme
;; interrupt handler and debugger read single character commands in cbreak
;; mode; when this happens, xscheme.el switches to special keymaps that bind
;; the single letter command keys to emacs functions that directly send the
;; character to the scheme process. Cmuscheme mode does *not* provide this
;; functionality. If you are a cscheme user, you may prefer to use the
;; xscheme.el/cscheme -emacs interaction.
;;
;; Here's a summary of the pros and cons, as I see them.
;; xscheme: Tightly integrated with inferior cscheme process! A few commands
;; not in cmuscheme. But. Integration is a bit of a hack. Input
;; history only keeps the immediately prior input. Bizarre
;; keybindings.
;;
;; cmuscheme: Not tightly integrated with inferior cscheme process. But.
;; Carefully integrated functionality with the entire suite of
;; comint-derived CMU process modes. Keybindings reminiscent of
;; Zwei and Hemlock. Good input history. A few commands not in
;; xscheme.
;;
;; It's a tradeoff. Pay your money; take your choice. If you use a Scheme
;; that isn't Cscheme, of course, there isn't a choice. Xscheme.el is *very*
;; Cscheme-specific; you must use cmuscheme.el. Interested parties are
;; invited to port xscheme functionality on top of comint mode...
;;; Code:
(require 'scheme)
(require 'comint)
;;; INFERIOR SCHEME MODE STUFF
;;;============================================================================
(defvar inferior-scheme-mode-hook nil
"*Hook for customising inferior-scheme mode.")
(defvar inferior-scheme-mode-map nil)
(cond ((not inferior-scheme-mode-map)
(setq inferior-scheme-mode-map
(copy-keymap comint-mode-map))
(define-key inferior-scheme-mode-map "\M-\C-x" ;gnu convention
'scheme-send-definition)
(define-key inferior-scheme-mode-map "\C-x\C-e" 'scheme-send-last-sexp)
(define-key inferior-scheme-mode-map "\C-c\C-l" 'scheme-load-file)
(define-key inferior-scheme-mode-map "\C-c\C-k" 'scheme-compile-file)
(scheme-mode-commands inferior-scheme-mode-map)))
;; Install the process communication commands in the scheme-mode keymap.
(define-key scheme-mode-map "\M-\C-x" 'scheme-send-definition);gnu convention
(define-key scheme-mode-map "\C-x\C-e" 'scheme-send-last-sexp);gnu convention
(define-key scheme-mode-map "\C-c\C-e" 'scheme-send-definition)
(define-key scheme-mode-map "\C-c\M-e" 'scheme-send-definition-and-go)
(define-key scheme-mode-map "\C-c\C-r" 'scheme-send-region)
(define-key scheme-mode-map "\C-c\M-r" 'scheme-send-region-and-go)
(define-key scheme-mode-map "\C-c\M-c" 'scheme-compile-definition)
(define-key scheme-mode-map "\C-c\C-c" 'scheme-compile-definition-and-go)
(define-key scheme-mode-map "\C-c\C-z" 'switch-to-scheme)
(define-key scheme-mode-map "\C-c\C-l" 'scheme-load-file)
(define-key scheme-mode-map "\C-c\C-k" 'scheme-compile-file) ;k for "kompile"
(defvar scheme-buffer)
(defun inferior-scheme-mode ()
"Major mode for interacting with an inferior Scheme process.
The following commands are available:
\\{inferior-scheme-mode-map}
A Scheme process can be fired up with M-x run-scheme.
Customisation: Entry to this mode runs the hooks on comint-mode-hook and
inferior-scheme-mode-hook (in that order).
You can send text to the inferior Scheme process from other buffers containing
Scheme source.
switch-to-scheme switches the current buffer to the Scheme process buffer.
scheme-send-definition sends the current definition to the Scheme process.
scheme-compile-definition compiles the current definition.
scheme-send-region sends the current region to the Scheme process.
scheme-compile-region compiles the current region.
scheme-send-definition-and-go, scheme-compile-definition-and-go,
scheme-send-region-and-go, and scheme-compile-region-and-go
switch to the Scheme process buffer after sending their text.
For information on running multiple processes in multiple buffers, see
documentation for variable scheme-buffer.
Commands:
Return after the end of the process' output sends the text from the
end of process to point.
Return before the end of the process' output copies the sexp ending at point
to the end of the process' output, and sends it.
Delete converts tabs to spaces as it moves back.
Tab indents for Scheme; with argument, shifts rest
of expression rigidly with the current line.
C-M-q does Tab on each line starting within following expression.
Paragraphs are separated only by blank lines. Semicolons start comments.
If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it."
(interactive)
(comint-mode)
;; Customise in inferior-scheme-mode-hook
(setq comint-prompt-regexp "^[^>\n]*>+ *") ; OK for cscheme, oaklisp, T,...
(scheme-mode-variables)
(setq major-mode 'inferior-scheme-mode)
(setq mode-name "Inferior Scheme")
(setq mode-line-process '(":%s"))
(use-local-map inferior-scheme-mode-map)
(setq comint-input-filter (function scheme-input-filter))
(setq comint-get-old-input (function scheme-get-old-input))
(run-hooks 'inferior-scheme-mode-hook))
(defvar inferior-scheme-filter-regexp "\\`\\s *\\S ?\\S ?\\s *\\'"
"*Input matching this regexp are not saved on the history list.
Defaults to a regexp ignoring all inputs of 0, 1, or 2 letters.")
(defun scheme-input-filter (str)
"Don't save anything matching inferior-scheme-filter-regexp"
(not (string-match inferior-scheme-filter-regexp str)))
(defun scheme-get-old-input ()
"Snarf the sexp ending at point"
(save-excursion
(let ((end (point)))
(backward-sexp)
(buffer-substring (point) end))))
(defun scheme-args-to-list (string)
(let ((where (string-match "[ \t]" string)))
(cond ((null where) (list string))
((not (= where 0))
(cons (substring string 0 where)
(scheme-args-to-list (substring string (+ 1 where)
(length string)))))
(t (let ((pos (string-match "[^ \t]" string)))
(if (null pos)
nil
(scheme-args-to-list (substring string pos
(length string)))))))))
(defvar scheme-program-name "scheme"
"*Program invoked by the run-scheme command")
;;;###autoload